<?
header("Content-type: application/vnd.ms-excel");
//header("Content-disposition: csv" . date("Y-m-d") . ".xls");

$filename = "SENARAI_PELAJAR_YG_MASIH_BELUM_MASUK_SEMULA";
//header( "Content-disposition: filename=$act.$extype");
header( "Content-disposition: filename=$filename.$extype");

$glue = '';
if ($extype == 'xls') $glue = "\t"; 
if ($extype == 'csv') $glue = ',';
 
//$flds = array('staff_name','bil_pelawat');
$arr = array("Nama Pelajar","No KP","No Matrik","Kursus", "Tarikh Keluar","Waktu Keluar");
$csv_output = join("$glue",$arr) . "\n"; 

$num = pg_num_rows($students);

for ($i=0;$i<$num;$i++) {
	$dat = pg_fetch_object($students,$i);
	$waktu_keluar = "$dat->jam_out:$dat->minit_out:";
	
	$arr = array();
	$arr[] = $dat->name;
	$arr[] = $dat->ic_new;
	$arr[] = $dat->nomatrik;
	$arr[] = $dat->course_code;
	$arr[] = $dat->tarikh_out;
	$arr[] = $waktu_keluar;
		
	$csv_output .= join("$glue",$arr) . "\n";
}

print $csv_output;
exit; 
?>